<?php
namespace App\Http\Controllers\Item\Fxotary\Admin;

use App\Service\Item\Fxotary\Admin\ActionService;
use Illuminate\Http\Request;

class ActionController extends BaseController
{
    //项目菜单

    public function __construct(ActionService $service)
    {
        $this->db = $service;
    }

    //列表
    public function leftMenu(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $token = $request->post('token', '');
        $res = $this->db->leftMenu($token);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //列表
    public function getIndex(Request $request)
    {
        $token = $request->post('token', '');
        $type = $request->post('type', 0); //1前台，2后台
        $res = $this->db->getIndex($token, $type);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //一个
    public function getOne(Request $request)
    {
        $id = $request->post('id');
        $res = $this->db->getOne($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['title'] = $request->post('title');
        $pas['pid'] = $request->post('pid', 0);
        $pas['link'] = $request->post('link');
        if (!$pas['title']) {
            return $this->toJson(-2, '功能名称必须的');
        }
        $res = $this->db->modify($id, $pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0);
    }
}